package com.piao.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.piao.R;
import com.piao.bean.Movies;
import com.piao.manager.ImageLoader;

import java.util.List;

/**
 * Created by guoliangli on 2017/4/11.
 */

public class HomeMovieAdapter extends RecyclerView.Adapter<HomeMovieAdapter.MoviesHolder> {

    private Context context;
    private List<Movies> list;
    private ImageLoader imageLoader;

    public HomeMovieAdapter(Context context, List<Movies> list) {
        this.context=context;
        this.list=list;
        imageLoader=new ImageLoader(context);
    }

    @Override
    public MoviesHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        int resId = R.layout.movie_item_layout;
        View view = LayoutInflater.from(context).inflate(resId, parent, false);
        MoviesHolder holder = new MoviesHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(MoviesHolder holder, int position) {
        imageLoader.loadUrlImage(list.get(position).img,holder.movie_icon);
        holder.movie_title.setText(list.get(position).titleCn);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }


    class MoviesHolder extends RecyclerView.ViewHolder{



        public ImageView movie_icon;
        public TextView movie_title;

        public MoviesHolder(View itemView) {
            super(itemView);
            movie_icon = (ImageView) itemView.findViewById(R.id.movie_icon);
            movie_title = (TextView) itemView.findViewById(R.id.movie_title);
        }
    }
}
